import java.lang.reflect.Field;
import java.util.Arrays;

public class TestDemo1027 {

    public static void main10(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String str="hello";//利用反射可以修改私有的属性
        Class cl=Class.class;
        Field field=cl.getDeclaredField("value");//
        field.setAccessible(true);
        char[] val= (char[]) field.get(str);
        val[0]='g';
        System.out.println(str);

    }
    public static void main9(String[] args) {
        String str = "hello";
        str = str + "World";
        str+="!!!";
        System.out.println(str);
    }


    public static void main(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello").intern();
        System.out.println(str1 == str2);
    }

    public static void main7(String[] args) {
        String str1 = null;
        String str2 = new String("aaaddddsss");
        System.out.println(str2.equals(null));
    }

    public static void func(String str, char[] array) {
        str = "adcfd";
        array[0] = 'g';
    }

    public static void main5(String[] args) {
        String str1 = "hello";
        char[] val = {'a'};
        System.out.println(str1);
        System.out.println(Arrays.toString(val));
        System.out.println("=====================");
        func(str1, val);
        System.out.println(str1);
        System.out.println(Arrays.toString(val));
    }


    public static void main6(String[] args) {
        String str1 = "hello";
        String str2 = "hel" + "lo";
        System.out.println(str1 == str2);//true
        System.out.println(str1.equals(str2));
        String str3 = new String("hel") + "lo";
        System.out.println(str1 == str3);//false
    }


    public static void main4(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");//因为第3行已经访问过
        System.out.println(str1 == str2);//false

        String str3 = "hello";
        System.out.println(str1 == str3);//true
    }


    public static void main3(String[] args) {
        String str = "hello!";
        System.out.println(str);
        String str2 = new String("This is a string");
        System.out.println(str2);
        char[] val = {'a', 'b', 'c', 'd', 'e'};
        String str3 = new String(val);
        System.out.println(str3);
    }


    public static void main2(String[] args) {
        MyArrayList<Integer> myArrayList1 = new MyArrayList<>();
        myArrayList1.add(1);
        myArrayList1.add(2);
        int val = (int) myArrayList1.getVal(1);
    }


    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add("he");
        myArrayList.add(2);
        int val = (int) myArrayList.getVal(1);
        System.out.println();
    }
}
